import {Entity, EntityDynamicQuery, MySql, Parent, Postgresql} from "../index";

@Entity("department_info")
class Department {
    private id: number = 0
    private name: string = ''
}

@Entity("user_info")
class User {
    id: number = 0
    name: string = ''
    age: number = 0
    department_id: number = 0
    @Parent({parentClass: Department, parentId: 'department_id'})
    department: object = {}

}


let postgresql = new MySql({
    "host": "192.168.1.52",
    "port": 5306,
    "database": "test_zh",
    "user": "root",
    "password": "Jimmy007",
    connectionLimit: 10
});

postgresql.connect().then(async () => {
    const entityDynamicQuery = new EntityDynamicQuery(postgresql, User, {enableSqlLog: true});
    let user = new User();
    user.name = 'zhang san'
    user.age = 10
    user.department_id = 1
    user = (await entityDynamicQuery.save(user))!;
    console.log(user)
    console.log(await entityDynamicQuery.findAll({}))
    console.log(await entityDynamicQuery.findOne({}));
    console.log(await entityDynamicQuery.navigationFindOne({}));
});